package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.wms.domain.WmsStock;
import com.ruoyi.wms.service.IWmsStockService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 仓库Controller
 * 
 * @author ruoyi
 * @date 2022-02-23
 */
@RestController
@RequestMapping("/wms/stock")
public class WmsStockController extends BaseController
{
    @Resource
    private IWmsStockService wmsStockService;

    /**
     * 查询仓库列表
     */
    @PreAuthorize(hasPermi = "wms:stock:list")
    @GetMapping("/list")
    public TableDataInfo list(WmsStock wmsStock){
        startPage();
        List<WmsStock> list = wmsStockService.selectWmsStockList(wmsStock);
        return getDataTable(list);
    }
  /**
     * 查询仓库列表
     */
    @PreAuthorize(hasPermi = "wms:stock:list")
    @GetMapping("/uuid")
    public TableDataInfo listStockUuid(WmsStock wmsStock){
        startPage();
        List<WmsStock> list = wmsStockService.listStockUuid(wmsStock);
        return getDataTable(list);
    }
    /**
     * 按仓库类别多选查询仓库列表
     */
    @PreAuthorize(hasPermi = "wms:stock:list")
    @GetMapping("/listStockByWmsDictStockType/{wmsDictStockType}")
    public TableDataInfo listByWmsDictStockType(@PathVariable String[] wmsDictStockType)
    {
        startPage();
        List<WmsStock> list = wmsStockService.listByWmsDictStockType(wmsDictStockType);
        return getDataTable(list);
    }

    /**
     * 导出仓库列表
     */
    @PreAuthorize(hasPermi = "wms:stock:export")
    @Log(title = "仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsStock wmsStock) throws IOException
    {
        List<WmsStock> list = wmsStockService.selectWmsStockList(wmsStock);
        ExcelUtil<WmsStock> util = new ExcelUtil<WmsStock>(WmsStock.class);
        util.exportExcel(response, list, "仓库数据");
    }

    /**
     * 获取仓库详细信息
     */
    @PreAuthorize(hasPermi = "wms:stock:query")
    @GetMapping(value = "/{stockUuid}")
    public AjaxResult getInfo(@PathVariable("stockUuid") String stockUuid)
    {
        return AjaxResult.success(wmsStockService.selectWmsStockByStockUuid(stockUuid));
    }

    /**
     * 新增仓库
     */
    @PreAuthorize(hasPermi = "wms:stock:add")
    @Log(title = "仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsStock wmsStock)
    {
        wmsStock.setCreateBy(SecurityUtils.getUsername());
        return toAjax(wmsStockService.insertWmsStock(wmsStock));
    }

    /**
     * 修改仓库
     */
    @PreAuthorize(hasPermi = "wms:stock:edit")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsStock wmsStock)
    {
        return toAjax(wmsStockService.updateWmsStock(wmsStock));
    }
 /**
     * 修改仓库
     */
    @PreAuthorize(hasPermi = "wms:stock:edit")
    @Log(title = "仓库", businessType = BusinessType.UPDATE)
    @PutMapping("/all")
    public AjaxResult editAll(@RequestBody WmsStock wmsStock)
    {
        int i = wmsStockService.updateWmsStockAll(wmsStock);
        return toAjax(i);
    }

    /**
     * 删除仓库
     */
    @PreAuthorize(hasPermi = "wms:stock:remove")
    @Log(title = "仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockUuids}")
    public AjaxResult remove(@PathVariable String[] stockUuids)
    {
        int i= wmsStockService.deleteWmsStockByStockUuids(stockUuids);
        return toAjax(i);
    }
}
